package suport;

public class ListNode {

    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public String toStringLink(){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        while (next!=null){
            stringBuilder.append(val+"->");
        }
        int length = stringBuilder.length();
        stringBuilder.replace(length-2,length-1,"]");
        return stringBuilder.toString();
    }

    @Override
    public String toString(){
        String result ="";
        result = result+"[";
        while (next!=null){
            result=val+"->";
        }
        int length = result.length();
        result=result+"]";
        return result;
    }

}
